package com.conversationboard.batch.jobs.recordthreadreads;

import java.sql.SQLException;
import java.util.List;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.conversationboard.cache.readcounter.ReadCounterCache;
import com.conversationboard.cache.readcounter.ThreadCounter;
import com.conversationboard.site.Site;

/**
 * Get the 50 most popular threads and copy them into a static list for reading with no contention on the Site object.
 * 
 * @author Keith Watson
 *
 */

public class RecordThreadReads implements Job {

	public void execute(JobExecutionContext context) throws JobExecutionException {

		try {
			List<ThreadCounter> mostPopularThreads = ReadCounterCache.getInstance().getMostPopularThreads();
			Site.setMostPopularThreads(mostPopularThreads);

			/* Re-clear the cache, to start counting threads again */

			ReadCounterCache.getInstance().clear();

		} catch (SQLException e) {
			throw new JobExecutionException(e);
		}

	}

}
